package com.zbkj.admin.controller;

import com.zbkj.admin.service.AdminProductHandler;
import com.zbkj.common.model.product.Product;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.product.AdminProductQueryRequest;
import com.zbkj.common.request.product.AdminProductSaveRequest;
import com.zbkj.common.response.CommonResult;
import com.zbkj.common.response.product.ClientProductResponse;
import com.zbkj.common.validation.CreateValidatorGroup;
import com.zbkj.common.validation.UpdateValidatorGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther:
 * @Date: 2024/9/12 13:46
 * @Description:
 */
@RestController
@RequestMapping("api/admin/product")
@Api(tags = "服务端-商品管理服务")
public class AdminProductController {

    @Autowired
    private AdminProductHandler adminProductHandler;

    @ApiOperation(value = "商品列表")
    @PostMapping(value = "/list")
    public CommonResult<CommonPage<Product>> list(@RequestBody @Validated AdminProductQueryRequest queryRequest) {
        return CommonResult.success(CommonPage.restPage(adminProductHandler.list(queryRequest)));
    }


    @ApiOperation(value = "新增商品")
    @PostMapping(value = "/save")
    public CommonResult save(@RequestBody @Validated({CreateValidatorGroup.class}) AdminProductSaveRequest productRequest) {
        adminProductHandler.saveOrUpdate(productRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "编辑商品")
    @PostMapping(value = "/update")
    public CommonResult update(@RequestBody @Validated({UpdateValidatorGroup.class}) AdminProductSaveRequest productRequest) {
        adminProductHandler.saveOrUpdate(productRequest);
        return CommonResult.success();
    }

    @ApiOperation(value = "获取商品信息")
    @GetMapping(value = "/getInfo/{id}")
    public CommonResult<Product> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(adminProductHandler.getInfo(id));
    }

    @ApiOperation(value = "商品上下架处理")
    @GetMapping(value = "/updateStatus/{id}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "商品ID"),
            @ApiImplicitParam(name = "status",value = "商品状态 0 上架 1下架"),
    })
    public CommonResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        adminProductHandler.updateStatus(id,status);
        return CommonResult.success();
    }

    @ApiOperation(value = "删除商品")
    @GetMapping(value = "/delInfo/{id}")
    public CommonResult delInfo(@PathVariable("id") Long id) {
        adminProductHandler.delProduct(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "获取充值商品集合")
    @GetMapping(value = "/getBuyProductList/{queryType}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryType",value = "获取商品类型 1 订阅包和流量包 2 报告包")
    })
    public CommonResult<List<Product>> getBuyProductList(@PathVariable("queryType") Integer queryType) {
        return CommonResult.success(adminProductHandler.getBuyProductList(queryType));
    }

}
